/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package trace;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 *
 * @author Julien Cassis
 */
public class Main {

    static Reader readFile;
    static Writer writeFile;
    private static final int MAX_BIT = 20;
    private static final int MAX_HISTORY = 8;

    //private static final String inpath = "/home/phil/School/ECSE-425/project/branchprediction/trace/";
    //private static final String outpath = "/home/phil/School/ECSE-425/project/results/";
    private static final String inpath = "C:\\Users\\Julien Cassis\\Documents\\McGill\\ECSE 425 - Computer Organisation and Architecture\\Project\\";
   private static final String outpath = "C:\\Users\\Julien Cassis\\Documents\\McGill\\ECSE 425 - Computer Organisation and Architecture\\Project\\";
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String[] tname={"STATIC","N-BIT", "CORRELATED","TOURNAMENT"};
        String[] fname={"FP","MM","INT","SERV"};

        ExecutorService executor = Executors.newFixedThreadPool(4);
        
        //static

        for(int i=0;i<fname.length;i++){
            for(int j=0;j<2;j++){
            System.out.println("File: " + fname[i] + " predict scheme: " + j);
            readFile = new Reader(inpath + fname[i] +".trace");
            writeFile = new Writer(outpath + tname[0] + "/" + fname[i] + "/" + fname[i] + "_" + j + ".csv");
            staticPredictor pred = new staticPredictor(readFile,writeFile,j);
            executor.execute(pred);
            }
        }
        
        // n-bit Predictor
        for(int i=0;i<fname.length;i++){
            for(int bits=1;bits<=MAX_BIT;bits++){
                    System.out.println("File: " + fname[i] + " predict scheme: " + bits + "'s buffer");
                    readFile = new Reader(inpath + fname[i] +".trace");
                    writeFile = new Writer(outpath + tname[1] + "/" + fname[i] + "/" + fname[i] + "_" + bits + "b.csv");
                    predictorBuffer pred = new predictorBuffer(readFile,writeFile,bits);
                    executor.execute(pred);
            }
        }
   
        // correlated predictor
        for(int i = 0 ; i < fname.length; i++){
                for(int bits = 1; bits <= MAX_BIT; bits++) {
                    for(int hist=8; hist<=MAX_HISTORY; hist++) {
                            System.out.println("File: " + fname[i] + " correlary(" + hist + "," + bits + ")");
                            readFile = new Reader(inpath + fname[i] +".trace");
                            writeFile = new Writer(outpath + tname[2] + "/" + fname[i] + "/" + fname[i] + "_" + hist + "x" + bits + "bx" + ".csv");
                            CorrelatedPredictor pred = new CorrelatedPredictor(readFile, writeFile, hist, bits);
                            //pred.run();
                            executor.execute(pred);
                    }
                }
        }

        // tournament
        for(int i=0;i<fname.length;i++){
            for(int bits = 1; bits <= MAX_BIT; bits++) {
            System.out.println("File: " + fname[i] + " tournament");
            readFile = new Reader(inpath + fname[i] +".trace");
            writeFile = new Writer(outpath + tname[3] + "/" + fname[i] + "/" + fname[i] + "_" + bits + "b.csv");
            TournamentPredictor pred = new TournamentPredictor(readFile, writeFile,bits);
            //pred.run();
            executor.execute(pred);
            }
        }
        executor.shutdown();
    }
}
